package com.zs.blog.model;

import com.zs.blog.constant.enums.ResponseResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Title: ResponseResult
 * @Author zs
 * @Package com.zs.blog.model
 * @Date 2024/9/24 22:08
 * @description: 响应结果类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {

    private Boolean status;
    private int code;
    private String message;
    private T data;

    public ResponseResult(Boolean status, ResponseResultEnum resultEnum) {
        this.status = status;
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
    }

    public ResponseResult(Boolean status, ResponseResultEnum resultEnum, T data) {
        this.status = status;
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.data = data;
    }

    public ResponseResult(Boolean status,String message) {
        this.status = status;
        this.message = message;
    }

    public static <E> ResponseResult<E> success(E data) {
        return new ResponseResult<E>(true,ResponseResultEnum.SUCCESS, data);
    }

    public static <E> ResponseResult<E> success() {
        return new ResponseResult<E>(true,ResponseResultEnum.SUCCESS,null);
    }

    public static <E> ResponseResult<E> success(ResponseResultEnum resultEnum) {
        return new ResponseResult<E>(true,resultEnum, null);
    }

    public static <E> ResponseResult<E> failure() {
        return new ResponseResult<E>(false,ResponseResultEnum.FAILURE);
    }

    public static <E> ResponseResult<E> failure(String message) {
        return new ResponseResult<E>(false,message);
    }

    public static <E> ResponseResult<E> failure(ResponseResultEnum resultEnum) {
        return new ResponseResult<E>(false,resultEnum);
    }

}
